colorAdminApp.service('loginService',function() {
   	    
	this.login=function(username,password,$scope,$http,$state){
		var messageDic={}
		messageDic["Bad credentials"]="用户名或密码错误";
		messageDic["User account is locked"]="用户被锁定，请联系管理员解锁。";
		messageDic["Maximum sessions of 1 for this principal exceeded"]="该用户已在别处登录，请先退出后再登录，或联系管理员踢除已登录账户。";
		messageDic["User credentials have expired"]="密码已过期。";
		messageDic["User account has expired"]="账号已过期。";
		var entity={"responseType":"json"};
		entity["username"]=username;
		entity["password"]=password;
		$http.post('login',{params:entity}).success(function(data, status, headers, config) {
		 if(data.status==0){//登录失败
			 $scope.showMessage=true;
			 $scope.message=messageDic[data.message];
			 if(data.message=="User credentials have expired"){
				 $state.go("userPasswordUpdateForExpired",{"username":data.data.username});
			 }
		 }
		 if(data.status==1){
			 $state.go("main",{"username":data.data.username,"photo":data.data.photo});
		 }
		 }).error(function(data, status, headers, config) {
	    	alert(data);
      });  
		
		
	};
	
});